<?php
	function redirection($page)
	{
		header("Location: $page");
		exit;
	}
	
	function isLocalServer()
	{
		if($_SERVER['SERVER_ADDR'] == "127.0.0.1")
			return true;
		else
			return false;
	}
	
	function echoNumJS($name, $num)
	{
		echo "<script>var $name = $num;</script>";
	}
	
	function echoStrJS($name, $str)
	{
		echo "<script>var $name = '$str';</script>";
	}
	
	function debug($var)
	{
		echo STRfromDB("|||||||--- $var ---|||||||<script>alert('$var');</script>");
		$fp = fopen('./debug.txt', 'a');
		fwrite($fp, "\n" . $var);
		fclose($fp);
	}
	
	function STRtoDB($str)
	{
		//$str = mysql_real_escape_string($str);
		return $str;
	}
	
	function STRfromDB($str)
	{
		$str = htmlentities($str);
		return $str;
	}
	
	function NUMtoDB($num)
	{
		$num = intval($num);
		return $num;
	}
	
	function password($pw)
	{
		if($pw == '')
			return '';
		$pw = md5($pw);
		return $pw;
	}
	
	function getLink()
	{
		return $_SERVER['REQUEST_URI'];
	}
	
	function getPage()
	{
		$arrayPage = explode( "/", $_SERVER['SCRIPT_FILENAME']);
		return $arrayPage[sizeof($arrayPage) - 1];
	}
	
	function isPage($page)
	{
		if(getPage() == $page . '.php')
			return true;
		return false;
	}
	
	function sessionReset()
	{
		session_unset();
		session_destroy();
	}
	
	function createSession($identifiant)
	{
		$_SESSION['identifiant'] = $identifiant;
		$_SESSION['type'] = typeUser($identifiant); //à faire en fonction de la base de donnée !!!
		redirection('./index.php');	
	}
	
	function admin()
	{
		if(!guest() && $_SESSION['type'] == MEMBRE_ADMIN)
			return true;
		return false;
	}
	
	function user()
	{
		if(!guest() && $_SESSION['type'] == MEMBRE_USER)
			return true;
		return false;
	}
	
	function guest()
	{
		if(isset($_SESSION['identifiant']))
			return false;
		return true;
	}
?>